home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / utility / utilgraf / newicndt.lha / NewIconDT / Sources / classbase.c next >
C/C++ Source or Header  |  1996-10-24  |  4KB  |  144 lines

  1.  
  2. /******************************************************************************
  3.  *
  4.  * NewIcon Datatype
  5.  *
  6.  * Written by Pascal Hurni and Christian Buchner and David N. Junod
  7.  *
  8.  ******************************************************************************
  9.  * classbase.c
  10.  *
  11.  */
  12.  
  13. #include "classbase.h"
  14.  
  15.  
  16. /*****************************************************************************/
  17.  
  18. Class *__asm ObtainClassEngine (register __a6 struct ClassBase *cb)
  19. {
  20.     return (cb->cb_Class);
  21. }
  22.  
  23. /*****************************************************************************/
  24.  
  25. struct Library *__asm LibInit (register __d0 struct ClassBase *cb, register __a0 BPTR seglist, register __a6 struct Library * sysbase)
  26. {
  27.     cb->cb_SegList = seglist;
  28.     cb->cb_SysBase = sysbase;
  29.     InitSemaphore (&cb->cb_Lock);
  30.     if (cb->cb_SysBase->lib_Version >= 39)
  31.     {
  32.         cb->cb_IntuitionBase = OpenLibrary ("intuition.library",39);
  33.         cb->cb_GfxBase       = OpenLibrary ("graphics.library", 39);
  34.         cb->cb_DOSBase       = OpenLibrary ("dos.library",      39);
  35.         cb->cb_UtilityBase   = OpenLibrary ("utility.library",  39);
  36.         cb->cb_NewIconBase   = OpenLibrary ("newicon.library",  37);
  37.         return cb;
  38.     }
  39.     else
  40.     {
  41.         return NULL;
  42.     }
  43. }
  44.  
  45. /*****************************************************************************/
  46.  
  47. LONG __asm LibOpen (register __a6 struct ClassBase *cb)
  48. {
  49.     LONG retval = (LONG) cb;
  50.     BOOL success = TRUE;
  51.     
  52.     ObtainSemaphore (&cb->cb_Lock);
  53.     
  54.     /* Use an internal use counter */
  55.     cb->cb_Lib.lib_OpenCnt++;
  56.     cb->cb_Lib.lib_Flags &= ~LIBF_DELEXP;
  57.     
  58.     if (cb->cb_Lib.lib_OpenCnt == 1)
  59.     {
  60.         if (cb->cb_Class == NULL)
  61.         {
  62.             success = FALSE;
  63.             if (cb->cb_IFFParseBase = OpenLibrary ("iffparse.library", 39))
  64.                 if (cb->cb_DataTypesBase = OpenLibrary ("datatypes.library", 39))
  65.                     if (cb->cb_SuperClassBase = OpenLibrary ("datatypes/picture.datatype", 39))
  66.                         if (cb->cb_Class = initClass (cb))
  67.                             success = TRUE;
  68.         }
  69.     }
  70.     
  71.     if (!success)
  72.     {
  73.         CloseLibrary (cb->cb_SuperClassBase);
  74.         CloseLibrary (cb->cb_DataTypesBase);
  75.         CloseLibrary (cb->cb_IFFParseBase);
  76.         cb->cb_IFFParseBase = cb->cb_DataTypesBase = cb->cb_SuperClassBase = NULL;
  77.         
  78.         cb->cb_Lib.lib_OpenCnt--;
  79.         retval = NULL;
  80.     }
  81.     
  82.     ReleaseSemaphore (&cb->cb_Lock);
  83.     
  84.     return (retval);
  85. }
  86.  
  87. /*****************************************************************************/
  88.  
  89. LONG __asm LibClose (register __a6 struct ClassBase *cb)
  90. {
  91.     LONG retval = NULL;
  92.     
  93.     ObtainSemaphore (&cb->cb_Lock);
  94.     
  95.     if (cb->cb_Lib.lib_OpenCnt)
  96.     cb->cb_Lib.lib_OpenCnt--;
  97.     
  98.     if ((cb->cb_Lib.lib_OpenCnt == 0) && cb->cb_Class)
  99.     {
  100.         if (FreeClass (cb->cb_Class))
  101.         {
  102.             cb->cb_Class = NULL;
  103.             CloseLibrary (cb->cb_SuperClassBase);
  104.             CloseLibrary (cb->cb_DataTypesBase);
  105.             CloseLibrary (cb->cb_IFFParseBase);
  106.         }
  107.         else
  108.         cb->cb_Lib.lib_Flags |= LIBF_DELEXP;
  109.     }
  110.     
  111.     if (cb->cb_Lib.lib_Flags & LIBF_DELEXP)
  112.     retval = LibExpunge (cb);
  113.     
  114.     ReleaseSemaphore (&cb->cb_Lock);
  115.     
  116.     return (retval);
  117. }
  118.  
  119. /*****************************************************************************/
  120.  
  121. LONG __asm LibExpunge (register __a6 struct ClassBase *cb)
  122. {
  123.     BPTR seg = cb->cb_SegList;
  124.     
  125.     Remove ((struct Node *) cb);
  126.     
  127.     CloseLibrary (cb->cb_NewIconBase);
  128.     CloseLibrary (cb->cb_UtilityBase);
  129.     CloseLibrary (cb->cb_DOSBase);
  130.     CloseLibrary (cb->cb_GfxBase);
  131.     CloseLibrary (cb->cb_IntuitionBase);
  132.     
  133.     FreeMem ((APTR)((ULONG)(cb) - (ULONG)(cb->cb_Lib.lib_NegSize)), cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
  134.     
  135.     return ((LONG) seg);
  136. }
  137.  
  138. /*****************************************************************************/
  139.  
  140. LONG __asm LibReserved(register __a6 struct ClassBase *cb)
  141. {
  142.     return 0;
  143. }
  144.